Method and Apparatus for Controlling Application Program, and Electronic Device

ABSTRACT

Embodiments of the present invention relate to telecommunications technologies, so that in a state in which the electronic device is connected to an external audio device, a manner used by the electronic device to process an audio and video application program can be intelligentized. A sensor is disposed on at least one of the electronic device or the external audio device. The method includes: receiving, by the electronic device, a detection result signal sent by the sensor, where the detection result signal is a signal that carries a detection value obtained by means of detection by the sensor; determining, by the electronic device according to a preset correspondence and the detection value, an action performed by a user on the electronic device or the external audio device; and controlling, by the electronic device, an execution status of an audio and video application program according to the action.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.15/514,404, filed on Mar. 24, 2017, which is a National Stage ofInternational Application No. PCT/CN2014/087555, filed on Sept. 26,2014. Both of the aforementioned applications are hereby incorporated byreference in their entireties.

TECHNICAL FIELD

The present invention relates to telecommunications technologies, and inparticular, to a method and an apparatus for controlling an applicationprogram, and an electronic device.

BACKGROUND

Generally, an electronic device such as a mobile phone or a PDA(Personal Digital Assistant) can be connected to an external audiodevice such as a headset or a sound box. By means of a connection to aheadset, an audio output channel can be switched from a speaker or anearpiece that is disposed on a main body of an electronic device to theheadset, so as to facilitate usage by a user.

In the past, when audio is played by using a headset, if an applicationprogram associated with the audio may require to be controlled (forexample, the application program is started, paused, or converted), auser may require to manually operate an electronic device or a headsetconnected to the electronic device. For example, in cases such asgetting on a vehicle or crossing a road, a user may need to take off,from the head, a headset that is outputting audio. However, in thiscase, an application program associated with the audio does notautomatically stop running, and the user may require to manually operatean electronic device so that the application program can be stopped andplayback of the audio can be stopped. For another example, when a mobilephone is connected to a Bluetooth headset, to switch an audio outputchannel of an incoming call to an earpiece of the mobile phone, a usermay require to perform manual switch by operating the Bluetooth headset.

In a state in which an electronic device is connected to a headset,control of an application program associated with audio depends on amanual operation of a user and cannot be automatically performed. Thecontrol of the application program is complex, and is not easy for theuser to operate.

SUMMARY

Embodiments of the present invention provide a method and an apparatusfor controlling an application program, and an electronic device, sothat a manner used by the electronic device to control, in a state inwhich the electronic device is connected to a headset, an audio andvideo application program can be simpler, and a user operates easily.

To achieve the foregoing objective, the following technical solutionsare used in the embodiments of the present invention.

According to a first aspect, a method for controlling an applicationprogram is provided, where the method is applied to an electronic deviceconnected to an external audio device, and a sensor is disposed on atleast one of the electronic device or the external audio device, wherewhen a sensor is disposed on the electronic device, the sensor disposedon the electronic device is configured to detect that a user moves theelectronic device close to and/or away from the head of the user, andwhen a sensor is disposed on the external audio device, the sensordisposed on the external audio device is configured to detect that theuser wears and/or takes off the external audio device. The methodincludes receiving, by the electronic device, a detection result signalsent by the sensor that is disposed on at least one of the electronicdevice or the external audio device, where the detection result signalcarries a detection value obtained by means of detection by the sensor.The method also includes determining, by the electronic device accordingto a preset correspondence between a user action and a detection valueand according to the detection value carried in the detection resultsignal, an action performed by the user on the electronic device or theexternal audio device, where the action performed by the user on theelectronic device includes that the user moves the electronic deviceclose to or away from the head of the user, and the action performed bythe user on the external audio device includes that the user wears ortakes off the external audio device. Additionally, the method includescontrolling, by the electronic device, an execution status of an audioand video application program according to the action performed by theuser on the electronic device or the external audio device.

With reference to the first aspect, in a first possible implementationmanner of the first aspect, a sensor is disposed on the external audiodevice; the external audio device is a headset; and the controlling, bythe electronic device, an execution status of an audio and videoapplication program according to the action performed by the user on theexternal audio device specifically includes: determining, by theelectronic device, a current execution status of the audio and videoapplication program, where the execution status includes not started,running, and paused; and when the action performed by the user on theheadset is taking off the headset and the execution status is running,controlling, by the electronic device, the audio and video applicationprogram to be paused; or when the action performed by the user on theheadset is taking off the headset and the execution status is notstarted or is paused, controlling, by the electronic device, the audioand video application program to remain not started or remain paused; orwhen the action performed by the user on the headset is wearing theheadset and the execution status is not started or is paused,controlling, by the electronic device, the audio and video applicationprogram to start to run or continue running; or when the actionperformed by the user on the headset is wearing the headset and theexecution status is running, controlling, by the electronic device, theaudio and video application program to remain running.

With reference to the first aspect or the first possible implementationmanner of the first aspect, in a second possible implementation mannerof the first aspect, in a case in which there are multiple audio andvideo application programs, before the controlling, by the electronicdevice, an execution status of an audio and video application programaccording to the action performed by the user on the electronic deviceor the external audio device, the method further includes: determining,by the electronic device, that an audio and video application programhaving a highest priority is an audio and video application program thatmay require to be controlled according to the action performed by theuser on the electronic device or the external audio device.

With reference to the first aspect, in a third possible implementationmanner of the first aspect, a sensor is disposed on the electronicdevice, the audio and video application program is a call application,and the controlling, by the electronic device, an execution status of anaudio and video application program according to the action performed bythe user on the electronic device specifically includes: when theelectronic device receives an incoming call and the action performed bythe user on the electronic device is moving the electronic device closeto the head of the user, automatically answering, by the electronicdevice, the call, and controlling call audio to be output from abuilt-in earpiece of the electronic device; or when the electronicdevice is in a call and the action performed by the user on theelectronic device is moving the electronic device close to the head ofthe user, controlling, by the electronic device, call audio to be outputfrom a built-in earpiece of the electronic device; or when theelectronic device is in a call and the action performed by the user onthe electronic device is moving the electronic device away from the headof the user, controlling, by the electronic device, call audio to beoutput from the external audio device.

With reference to the third possible implementation manner of the firstaspect, in a fourth possible implementation manner, when the electronicdevice receives an incoming call and the action performed by the user onthe electronic device is moving the electronic device close to the headof the user, the automatically answering, by the electronic device, thecall, and controlling call audio to be output from a built-in earpieceof the electronic device specifically includes: when the electronicdevice receives the incoming call and the action performed by the useron the electronic device is moving the electronic device close to thehead of the user, determining, by the electronic device, whether agesture answer function has been activated for the electronic device,where the gesture answer function refers to a function for theelectronic device to identify a user gesture and respond to theidentified user gesture to automatically answer the call; and when thegesture answer function has been activated for the electronic device,automatically answering, by the electronic device, the call, andcontrolling the call audio to be output from the built-in earpiece ofthe electronic device.

With reference to the third or the fourth possible implementation mannerof the first aspect, in a fifth possible implementation manner, theautomatically answering, by the electronic device, the call, andcontrolling the call audio to be output from the built-in earpiece ofthe electronic device specifically includes: determining, by theelectronic device, whether an intelligent call switching function hasbeen activated for the electronic device, where the intelligent callswitching function refers to a function for the electronic device toautomatically respond to the action performed by the user on theelectronic device to automatically switch a call audio output channel;and when the intelligent call switching function has been activated forthe electronic device, automatically answering, by the electronicdevice, the call, and controlling the call audio to be output from thebuilt-in earpiece of the electronic device.

With reference to the fifth possible implementation manner of the firstaspect, in a sixth possible implementation manner of the first aspect,when the intelligent call switching function is not activated for theelectronic device, the method further includes: automatically answering,by the electronic device, the call, and controlling the call audio to beoutput from the external audio device.

With reference to the first aspect or the first to the sixth possibleimplementation manners of the first aspect, in a seventh possibleimplementation manner of the first aspect, the sensor includes at leastone of an optical proximity sensor, a light sensor, or a temperaturesensor.

According to a second aspect, an apparatus for controlling anapplication program is provided, where the apparatus is applied to anelectronic device connected to an external audio device, and a sensor isdisposed on at least one of the electronic device or the external audiodevice, where when a sensor is disposed on the electronic device, thesensor disposed on the electronic device is configured to detect that auser moves the electronic device close to and/or away from the head ofthe user, and when a sensor is disposed on the external audio device,the sensor disposed on the external audio device is configured to detectthat the user wears and/or takes off the external audio device. Theapparatus includes a receiving unit, configured to receive a detectionresult signal sent by the sensor that is disposed on at least one of theelectronic device or the external audio device, where the detectionresult signal carries a detection value obtained by means of detectionby the sensor. The apparatus also includes a determining unit,configured to determine, according to a preset correspondence between auser action and a detection value and according to the detection valuecarried in the detection result signal, an action performed by the useron the electronic device or the external audio device, where the actionperformed by the user on the electronic device includes that the usermoves the electronic device close to or away from the head of the user,and the action performed by the user on the external audio deviceincludes that the user wears or takes off the external audio device.Additionally, the apparatus includes a control unit, configured tocontrol an execution status of an audio and video application programaccording to the action performed by the user on the electronic deviceor the external audio device.

With reference to the second aspect, in a first possible implementationmanner of the second aspect, a sensor is disposed on the external audiodevice; the external audio device is a headset; and the control unitspecifically includes: an execution status determining module,configured to determine a current execution status of the audio andvideo application program, where the execution status includes notstarted, running, and paused; and an execution status control module,configured to: when the action performed by the user on the headset istaking off the headset and the execution status determining moduledetermines that the execution status is running, control the audio andvideo application program to be paused; or when the action performed bythe user on the headset is taking off the headset and the executionstatus determining module determines that the execution status is notstarted or is paused, control the audio and video application program toremain not started or remain paused; or when the action performed by theuser on the headset is wearing the headset and the execution statusdetermining module determines that the execution status is not startedor is paused, control the audio and video application program to startto run or continue running; or when the action performed by the user onthe headset is wearing the headset and the execution status determiningmodule determines that the execution status is running, control theaudio and video application program to remain running.

With reference to the second aspect or the first possible implementationmanner of the second aspect, in a second possible implementation mannerof the second aspect, the control unit is further configured to: in acase in which there are multiple audio and video application programs,determine that an audio and video application program having a highestpriority is an audio and video application program that may require tobe controlled by the control unit according to the action performed bythe user on the electronic device or the external audio device.

With reference to the second aspect, in a third possible implementationmanner of the second aspect, a sensor is disposed on the electronicdevice, the audio and video application program is a call application,and the control unit is specifically configured to: when the electronicdevice receives an incoming call and the action performed by the user onthe electronic device is moving the electronic device close to the headof the user, control the electronic device to automatically answer thecall, and control call audio to be output from a built-in earpiece ofthe electronic device; or when the electronic device is in a call andthe action performed by the user on the electronic device is moving theelectronic device close to the head of the user, control call audio tobe output from a built-in earpiece of the electronic device; or when theelectronic device is in a call and the action performed by the user onthe electronic device is moving the electronic device away from the headof the user, control call audio to be output from the external audiodevice.

With reference to the third possible implementation manner of the secondaspect, in a fourth possible implementation manner of the second aspect,the control unit is specifically configured to: when the electronicdevice receives an incoming call and the action performed by the user onthe electronic device is moving the electronic device close to the headof the user, determine whether a gesture answer function has beenactivated for the electronic device, where the gesture answer functionrefers to a function for the electronic device to identify a usergesture and respond to the identified user gesture to automaticallyanswer the call; and when the gesture answer function has been activatedfor the electronic device, control the electronic device toautomatically answer the call, and control the call audio to be outputfrom the built-in earpiece of the electronic device.

With reference to the third or the fourth possible implementation mannerof the second aspect, in a fifth possible implementation manner of thesecond aspect, the control unit is specifically configured to: determinewhether an intelligent call switching function has been activated forthe electronic device, where the intelligent call switching functionrefers to a function for the electronic device to automatically respondto the action performed by the user on the electronic device toautomatically switch a call audio output channel; and when theintelligent call switching function has been activated for theelectronic device, control the electronic device to automatically answerthe call, and control the call audio to be output from the built-inearpiece of the electronic device.

With reference to the fifth possible implementation manner of the secondaspect, in a sixth possible implementation manner of the second aspect,the control unit is further configured to: when the intelligent callswitching function is not activated for the electronic device, controlthe electronic device to automatically answer the call, and control thecall audio to be output from the external audio device.

According to a third aspect, an electronic device is provided, where theelectronic device is connected to an external audio device, a sensor isdisposed on at least one of the electronic device or the external audiodevice, where when a sensor is disposed on the electronic device, thesensor disposed on the electronic device is configured to detect that auser moves the electronic device close to and/or away from the head ofthe user, and when a sensor is disposed on the external audio device,the sensor disposed on the external audio device is configured to detectthat the user wears and/or takes off the external audio device; and theelectronic device includes: a receiver, configured to receive adetection result signal sent by the sensor that is disposed on at leastone of the electronic device or the external audio device, where thedetection result signal carries a detection value obtained by means ofdetection by the sensor; and a processor, configured to determine,according to a preset correspondence between a user action and adetection value and according to the detection value carried in thedetection result signal, an action performed by the user on theelectronic device or the external audio device, where the actionperformed by the user on the electronic device includes that the usermoves the electronic device close to or away from the head of the user,and the action performed by the user on the external audio deviceincludes that the user wears or takes off the external audio device,where the processor is further configured to control an execution statusof an audio and video application program according to the actionperformed by the user on the electronic device or the external audiodevice.

With reference to the third aspect, in a first possible implementationmanner of the third aspect, a sensor is disposed on the external audiodevice; the external audio device is a headset; and the processor isspecifically configured to: determine a current execution status of theaudio and video application program, where the execution status includesnot started, running, and paused; and when the action performed by theuser on the headset is taking off the headset and the execution statusis running, control the audio and video application program to bepaused; or when the action performed by the user on the headset istaking off the headset and the execution status is not started or ispaused, control the audio and video application program to remain notstarted or remain paused; or when the action performed by the user onthe headset is wearing the headset and the execution status is notstarted or is paused, control the audio and video application program tostart to run or continue running; or when the action performed by theuser on the headset is wearing the headset and the execution status isrunning, control the audio and video application program to remainrunning.

With reference to the third aspect or the first possible implementationmanner of the third aspect, in a second possible implementation mannerof the third aspect, the processor is further configured to: in a casein which there are multiple audio and video application programs,determine that an audio and video application program having a highestpriority is an audio and video application program that may require tobe controlled by the processor according to the action performed by theuser on the electronic device or the external audio device.

With reference to the third aspect, in a third possible implementationmanner of the third aspect, a sensor is disposed on the electronicdevice, the audio and video application program is a call application,and the processor is specifically configured to: when the electronicdevice receives an incoming call and the action performed by the user onthe electronic device is moving the electronic device close to the headof the user, control the electronic device to automatically answer thecall, and control call audio to be output from a built-in earpiece ofthe electronic device; or when the electronic device is in a call andthe action performed by the user on the electronic device is moving theelectronic device close to the head of the user, control call audio tobe output from a built-in earpiece of the electronic device; or when theelectronic device is in a call and the action performed by the user onthe electronic device is moving the electronic device away from the headof the user, control call audio to be output from the external audiodevice.

With reference to the third possible implementation manner of the thirdaspect, in a fourth possible implementation manner of the third aspect,the processor is specifically configured to: when the electronic devicereceives an incoming call and the action performed by the user on theelectronic device is moving the electronic device close to the head ofthe user, determine whether a gesture answer function has been activatedfor the electronic device, where the gesture answer function refers to afunction for the electronic device to identify a user gesture andrespond to the identified user gesture to automatically answer the call;and when the gesture answer function has been activated for theelectronic device, control the electronic device to automatically answerthe call, and control the call audio to be output from the built-inearpiece of the electronic device.

With reference to the third or the fourth possible implementation mannerof the third aspect, in a fifth possible implementation manner of thethird aspect, the processor is specifically configured to determinewhether an intelligent call switching function has been activated forthe electronic device, where the intelligent call switching functionrefers to a function for the electronic device to automatically respondto the action performed by the user on the electronic device toautomatically switch a call audio output channel; and when theintelligent call switching function has been activated for theelectronic device, control the electronic device to automatically answerthe call, and control the call audio to be output from the built-inearpiece of the electronic device.

With reference to the fifth possible implementation manner of the thirdaspect, in a sixth possible implementation manner of the third aspect,the processor is further configured to determine whether an intelligentcall switching function has been activated for the electronic device,where the intelligent call switching function refers to a function forthe electronic device to automatically respond to the action performedby the user on the electronic device to automatically switch a callaudio output channel; and when the intelligent call switching functionis not activated for the electronic device, control the electronicdevice to automatically answer the call, and control the call audio tobe output from the external audio device.

According to a method and an apparatus for controlling an applicationprogram, and an electronic device that are provided in the embodimentsof the present invention, in a state in which the electronic device isconnected to an external audio device, the electronic device candetermine, according to a detection value acquired by a sensor disposedon at least one of the electronic device or the external audio deviceand a preset correspondence between a user action and a detection value,an action performed by a user on the electronic device or the externalaudio device, and control an execution status of an audio and videoapplication program according to the action. The action performed by theuser on the electronic device or the external audio device implies acorresponding user requirement, and a mechanism provided by the presentinvention to the electronic device can determine the user action andcontrol the audio and video application program according to the useraction, that is, explore the corresponding user requirement that isimplied by the user action, and perform a corresponding control actionto satisfy the user requirement, which therefore can make a manner usedby the electronic device to control, in the state in which theelectronic device is connected to the external audio device, the audioand video application program simpler, so that the user operates easily.

BRIEF DESCRIPTION OF THE DRAWINGS

To describe the technical solutions in the embodiments of the presentinvention more clearly, the following briefly describes the accompanyingdrawings required for describing the embodiments or the prior art.Apparently, the accompanying drawings in the following description showmerely some embodiments of the present invention.

FIG. 1 is a schematic diagram of a headset according to an embodiment ofthe present invention;

FIG. 2 is a flowchart of a method for controlling an application programaccording to

Embodiment 1;

FIG. 3 is a flowchart showing that an electronic device controls anaudio and video application program according to Embodiment 2;

FIG. 4 is a flowchart showing that an electronic device controls anaudio and video application program according to Embodiment 3;

FIG. 5 is a flowchart showing that a mobile phone controls a callprogram according to Embodiment 4;

FIG. 6A is a schematic structural diagram of an apparatus forcontrolling an application program according to Embodiment 5;

FIG. 6B is another schematic structural diagram of an apparatus forcontrolling an application program according to Embodiment 5; and

FIG. 7 is a schematic structural diagram of an electronic deviceaccording to Embodiment 6.

DETAILED DESCRIPTION OF ILLUSTRATIVE EMBODIMENTS

The following clearly and completely describes the technical solutionsin the embodiments of the present invention with reference to theaccompanying drawings in the embodiments of the present invention.Apparently, the described embodiments are merely some but not all of theembodiments of the present invention.

At first, an audio device involved in the embodiments of the presentinvention is described. The audio device involved in the presentinvention refers to a device having an audio playback function. Audiodevices are classified into external audio devices and built-in audiodevices according to whether the audio devices are pluggable relative toan electronic device. The electronic device may be any mobile orportable electronic device, including but not limited to a mobile phone,a mobile computer, a tablet computer, and a Personal Digital Assistant(PDA). An external audio device may be connected to the electronicdevice in a wired or wireless manner for use. When not used, theexternal audio device may be physically disconnected from the electronicdevice. Such an external audio device may be, for example, a wiredheadset, a Bluetooth headset, or a sound box. A built-in audio device isdisposed inside the electronic device, for example, a built-inmicrophone of a mobile phone, or a speaker built in a tablet computer.

In the embodiments of the present invention, a sensor is disposed on atleast one of the electronic device or the external audio device.

For example, when the external audio device is a headset, the headsetmay be any wired or wireless headset, for example, a sound source lineheadset, an infrared headset, or a Bluetooth headset. According toshapes, the headset may be a headset in any shape, for example, in-ear,headphone, or ear-bud. As shown in FIG. 1, in addition to having aspeaker of an ordinary headset, that is, having an audio playbackfunction, the headset involved in the embodiments of the presentinvention may further be provided with a sensor, where the sensor isconfigured to detect a usage state of the headset, and in particular, isconfigured to perform detection when a user wears and takes off theheadset. A type of the sensor that is disposed on the headset includesbut is not limited to an optical proximity sensor, a light sensor, and atemperature sensor. In the embodiments of the present invention, anytype of sensor described above may be disposed in the headset, or anycombination of multiple types of sensors may be disposed in the headset.

A basic working principle of an optical proximity sensor is that, lightemitted by the optical proximity sensor is reflected by a baffle object(such as a human face) that has a particular distance ahead of theoptical proximity sensor, and is then received by the optical proximitysensor. The optical proximity sensor determines an amount of light lossaccording to the received light, and determines the distance between thebaffle object and the optical proximity sensor according to the amountof light loss. The light sensor can convert received light intensityinto an electrical signal. The temperature sensor can convert a detectedtemperature into an electrical signal. As shown in FIG. 1, in theembodiments of the present invention, preferably, a sensor is disposedon the front of the headset, that is, on a housing on a face side of thespeaker of the headset. In addition, for the optical proximity sensor orthe light sensor, a side for emitting/receiving light and the face sideof the speaker face toward a same direction. For the temperature sensor,more preferably, the temperature sensor is disposed at a position on thehousing of the headset, where at the position, the temperature sensorcan be directly in contact with the body of the user (when the userwears the headset), and a finger of the user does not easily touch (forexample, is not touched when the user adjusts a position of the headset)the position. By means of such disposing, for the optical proximitysensor, when the user wears the headset, the optical proximity sensorcan obviously detect that an amount of light loss increases; and whenthe user takes off the headset, the optical proximity sensor canobviously detect that an amount of light loss decreases. For the lightsensor, when the user wears the headset, the light sensor can obviouslydetect that an amount of light loss decreases; and when the user takesoff the headset, the light sensor can obviously detect that an amount oflight loss increases. For the temperature sensor, when the user wearsthe headset, the temperature sensor can obviously detect thattemperature increases; and when the user takes off the headset, thetemperature sensor can obviously detect that temperature decreases.Comparatively, if the sensor is disposed at another position, forexample, the back or a side of the headset, a finger, instead of thebody, of the user mainly affects a detection value; therefore it isdifficult to distinguish a detection value corresponding to when theuser wears or takes off the headset.

For the electronic device, a sensor may also be disposed on a side of ascreen of the electronic device. The disposed sensor includes but is notlimited to one of or any combination of the foregoing three types ofsensors. However, the optical proximity sensor is preferred, and may bedisposed in an existing disposing manner. The sensor that is disposed onthe screen of the electronic device can detect an action of the userwhen the user moves the electronic device close to or away from the headof the user.

Embodiment 1

This embodiment is used to describe a method for controlling anapplication program provided in the present invention. The method isapplied to an electronic device connected to an external audio device.The electronic device is connected to the external audio device in awired or wireless manner. As described above, a sensor is disposed on atleast one of the electronic device or the external audio device. FIG. 2is a flowchart of a method for controlling an application programaccording to Embodiment 1. As shown in FIG. 2, the method includes thefollowing steps.

S21: The electronic device receives a detection result signal sent bythe sensor that is disposed on at least one of the electronic device orthe external audio device, where the detection result signal carries adetection value obtained by means of detection by the sensor.

In this step, the detection result signal received by the electronicdevice is from the sensor disposed on the external audio device, or isfrom the sensor disposed on the electronic device. Alternatively, theelectronic device receives both a detection result signal that is fromthe sensor disposed on the external audio device and a detection resultsignal that is from the sensor disposed on the electronic device.

First, that the detection result signal is from the sensor disposed onthe external audio device is described. After the external audio deviceis connected to the electronic device, the electronic device suppliespower to the sensor in the external audio device, and a detectionfunction is activated for the sensor. The sensor can maintain real-timemonitoring. The sensor acquires a detection value in real time. When auser wears or takes off the external audio device, the detection valuechanges suddenly. For example, an amount of light loss that is detectedby the optical proximity sensor increases or decreases obviously, wherethe detection value not only indicates a light intensity value, atemperature value, or another value, but also indicates a value of anelectrical signal that is converted from a light intensity signal, atemperature signal, or another signal, which are not differentiated inthe present invention. The detection value obtained by means ofdetection by the sensor is carried in the detection result signal, andis sent to the electronic device by using a connection between theexternal audio device and the electronic device. In this way, theelectronic device can acquire the detection value obtained by means ofdetection by the sensor.

Next, that the detection result signal is from the sensor disposed onthe electronic device is described. In a case of an incoming call, orduring a call, or in another case, the detection function is activatedfor the sensor that is disposed on the electronic device, and the sensordetects that the user moves the electronic device close to or away fromthe head. For example, when the user moves the electronic device closeto or away from the head, the detection value changes suddenly. Forexample, the amount of light loss that is detected by the opticalproximity sensor increases or decreases obviously. Similarly, thedetection value may be carried in the detection result signal, and sentto the electronic device by using a connection between the sensor andthe electronic device.

S22: The electronic device determines, according to a presetcorrespondence between a user action and a detection value and accordingto the detection value carried in the detection result signal, an actionperformed by the user on the electronic device or the external audiodevice.

In this embodiment, the electronic device may pre-store the presetcorrespondence that is used to determine the action performed by theuser on the electronic device or the external audio device. The presetcorrespondence refers to a correspondence, between the detection valueand the action performed by the user on the electronic device or theexternal audio device, and specifically may be preset by referring to aposition at which the sensor is disposed. For example, when a sensor isdisposed on the electronic device, because an action performed by a useron the electronic device may be required to be determined according to adetection value acquired by the sensor, a correspondence, between thedetection value and the action performed by the user on the electronicdevice may require. When a sensor is disposed on the external audiodevice, because an action performed by a user on the external audiodevice may require to be determined according to a detection valueacquired by the sensor, a correspondence, between the detection valueand the action performed by the user on the external audio device mayrequire. When a sensor is disposed on each of the electronic device andthe external audio device, a correspondence, between a detection valueand an action performed by a user on the electronic device, that is usedto determine the action performed by the user on the electronic device,and a correspondence, between a detection value and an action performedby a user on the external audio device, that is used to determine theaction performed by the user on the external audio device may be preset.The foregoing action performed by the user on the electronic deviceincludes at least that the user moves the electronic device close to oraway from the head of the user. The action performed by the user on theexternal audio device includes at least that the user wears or takes offthe external audio device. Certainly, subject to that the action can bedetected by the sensor, the action may further include holding theexternal audio device, adjusting only a position of the external audiodevice, or the like.

The preset correspondence may be more specifically a correspondencebetween a user action and a range of a detection value, for example, apreset range for determining whether the user moves the electronicdevice close to or away from the head of the user, or a preset range fordetermining whether the user wears or takes off the headset. Thefollowing provides descriptions by using an example of how to determine,according to a preset range, whether the user wears or takes off theheadset. How to determine, according to a preset range, whether the usermoves the electronic device close to or away from the head of the usermay be known by referring to the example. For example, according to anexperimental statistics result, a first preset range may be set, wherethe range represents that the user wears the headset; and a secondpreset range may be set, where the range represents that the user takesoff the headset. Specifically, after receiving a detection result signalsent by the headset, the electronic device reads a detection valuecarried in the detection result signal, and compares the detection valuewith the first preset range or the second preset range. If the detectionvalue falls within the first preset range, the electronic devicedetermines that an action is that the user wears the headset. If thedetection value falls within the second preset range, the electronicdevice determines that an action is that the user takes off the headset.

For example, whether a user performs an action of wearing or taking offa headset is determined by using a detection value acquired by anysensor of an optical proximity sensor, a light sensor, or a temperaturesensor, or by referring to detection values acquired by any two sensorsof the three, or by referring to detection values acquired by all thethree sensors. An amount of light loss acquired by the optical proximitysensor may be compared with a preset range. If the amount of light lossis within the first preset range, it is determined that the headset iscovered by an object, and it is determined that the action is that theuser wears the headset. If the amount of light loss is within the secondpreset range, it is determined that the headset is not covered by anyobject, and it is determined that the action is that the user takes offthe headset. A light intensity value or a temperature value acquired byusing the light sensor or the temperature sensor may also be determinedin a similar manner.

S23: The electronic device controls an execution status of an audio andvideo application program according to the action performed by the useron the electronic device or the external audio device.

In this step, the electronic device may control the application programaccording to the action determined in S22. In the present invention, howto control an application program in a state in which an electronicdevice is connected to an external audio device is considered, and theexternal audio device plays audio. Therefore, the controlled applicationprogram is an audio and video application program, where the audio andvideo application program refers to an application program that candisplay audio/video content to a user when the application program isrunning. The audio and video application program may be specifically amusic player, a video player, a game, a call application, or the like.An execution status of the audio and video application program includesbut is not limited to started, stopped, paused, and audio output channelswitching. The execution status is related to a specific audio and videoapplication program. For example, for the call application, an executionstatus of the call application includes at least connected,disconnected, a voice being output from a built-in microphone, or avoice being output from an external audio device. The controlled audioand video application program may be an audio and video applicationprogram that is currently running, where the currently running includesthat the audio and video application program is running in theforeground in the electronic device or the audio and video applicationprogram is running in the background; or the audio and video applicationprogram that is currently running may be an audio and video applicationprogram that is currently not started. Specifically, content of theaudio and video application program may be a paused state, or may be aplayback state.

There are multiple manners in which the electronic device controls anexecution status of an audio and video application program according tothe action performed by the user on the electronic device or theexternal audio device. For the action performed by the user on theelectronic device, for example, if the action is that the user moves theelectronic device close to the head, the electronic device may controlan audio output channel of the audio and video application program toswitch to an earpiece of the electronic device; if the action is thatthe user moves the electronic device away from the head, the electronicdevice may control an audio output channel of the audio and videoapplication program to switch to the external audio device. For theaction performed by the user on the external audio device, for example,if the action is that the user wears the headset, the electronic devicemay control the audio and video application program to start to run orcontinue running; if the action is that the user takes off the headset,the electronic device may control the audio and video applicationprogram to be paused.

According to the method for controlling an application program that isprovided in Embodiment 1, in a state in which the electronic device isconnected to an external audio device, the electronic device candetermine, according to a detection value acquired by a sensor disposedon at least one of the electronic device or the external audio deviceand a preset correspondence between a user action and a detection value,an action performed by a user on the electronic device or the externalaudio device, and control an execution status of an audio and videoapplication program according to the action. The action performed by theuser on the electronic device or the external audio device implies acorresponding user requirement, and a mechanism provided by thisembodiment to the electronic device can determine the user action andcontrol the audio and video application program according to the useraction, that is, explore the corresponding user requirement that isimplied by the user action, and perform a corresponding control actionto satisfy the user requirement, which therefore can make a manner usedby the electronic device to control, in the state in which theelectronic device is connected to the external audio device, the audioand video application program simpler, so that the user operates easily,and higher intelligentization is achieved.

Detection objects of the sensor disposed on the electronic device andthe sensor disposed on the external audio device are different, actionsdetermined according to detection values are different, and control overan execution status of an audio and video application program accordingto the actions is also different. The following separately providesdescriptions in Embodiment 2 and Embodiment 3.

Embodiment 2

Embodiment 2 is used to describe how an electronic device controls anaudio and video application program according to an action performed bya user on an external audio device. As shown in FIG. 3, the processspecifically includes.

S31: Determine an audio and video application program that may requireto be controlled.

When control over an execution status of an audio and video applicationprogram is triggered, in a case in which there are multiple audio andvideo application programs, the electronic device may determine that anaudio and video application program having a highest priority is anaudio and video application program that may require to be controlled,where a priority is specifically described below.

S32: An electronic device determines a current execution status of theaudio and video application program.

Generally, a user is accustomed to directly operating the electronicdevice to control a status of the audio and video application program.For example, in a state of wearing a headset, a user may manually pausea music player, and if subsequently that the user takes off the headsetis detected by a sensor, if switching the execution status of the audioand video application program is triggered immediately after the useraction of taking off or wearing the headset is detected, the electronicdevice may automatically switch the paused music player to continuing toplay, that is, an improper operation is caused. To prevent the improperoperation, the execution status of the audio and video applicationprogram may be determined before the execution status of the audio andvideo application program is controlled according to the actionperformed by the user on the external audio device, so that an adaptiveoperation can be performed according to the execution status. Theexecution status includes not started, running, paused, or the like.

After the current execution status of the audio and video applicationprogram is determined, the execution status of the audio and videoapplication program is controlled according to the action that isperformed by the user on the external audio device and that isdetermined in S22 in Embodiment 1. A specific control manner includesS33A to S33D.

S33A: When an action is that a user wears a headset and the executionstatus is not started or is paused, the electronic device controls theaudio and video application program to start to run or continue running.

S33B: When an action is that a user wears a headset and the executionstatus is running, the electronic device controls the audio and videoapplication program to remain running.

S33C: When an action is that a user takes off a headset and theexecution status is running, the electronic device controls the audioand video application program to be paused.

S33D: When an action is that a user takes off a headset and theexecution status is not started or is paused, the electronic devicecontrols the audio and video application program to remain not startedor remain paused.

For example, if the action is that the user wears the headset, and inthis case, an audio and video application program such as music, avideo, or a game already runs in the electronic device, and is in arunning state, the electronic device controls the audio and videoapplication program to continue running. If the action is that the usertakes off the headset, and in this case, an audio and video applicationprogram such as music, a video, or a game already runs in the electronicdevice, and is in a paused state, the electronic device automaticallyswitches the audio and video application program to a running state.

When a control manner for controlling an execution status of an audioand video application program according to a user action is set, alogical order of a current execution status and a control manner isconsidered, a control manner that does not comply with the logical orderis avoided. For example, if a current execution status is not started, acontrol manner that may be selected is starting or remaining notstarted, and when the user action is wearing the headset, acorresponding audio and video application program is controlled to bestarted but not to continue running (in respect of software, animplementation manner for controlling the application program to bestarted is different from an implementation manner for controlling theapplication program to continue running).

The electronic device not only may control one type of audio and videoapplication program, but also may control multiple types of audio andvideo application programs at the same time. For example, if the actionis that the user takes off the headset, and the electronic device is ina call, a mobile phone controls the call to automatically switch to anearpiece of the mobile phone. In this case, the electronic device notonly controls the headset to be turned off, but also controls theearpiece of the mobile phone to be started.

The following describes how to determine, based on a priority, an audioand video application program that may require to be controlledaccording to an action performed by a user on an external audio device,which is mentioned in S31. It may be understood that, how to determinean audio and video application program that may require to be controlledaccording to an action performed by a user on an electronic device issimilar.

In a task management module of the electronic device, information from atime at which an event occurs to a time at which the event ends isrecorded, where the information specifically includes times at whichapplication programs start to run, are paused, are stopped, and thelike. The electronic device may set, as a condition having a highestpriority, that an event occurs and a time at which the event occurs isthe closest to the present, and determines that an audio and videoapplication program that satisfies the condition is an audio and videoapplication program that may require to be controlled. For example, amusic player that is currently running has a highest priority because anoccurrence time for the music player is the present. If a user turns offthe music player and then opens an image browser, although a time atwhich an event of opening the image browser occurs is the closest to thepresent, the image browser is not associated with audio and is not anaudio and video application program; therefore, the electronic devicedetermines that the music player but not the image browser is an audioand video application program that may require to be controlled.

Alternatively, a user may preset a priority of an audio and videoapplication program. For example, a user may set a music player as anaudio and video application program having a highest priority, and whenan action is that the user wears a headset and an execution status ofthe music player is not started or is paused, the electronic devicedirectly makes the music player start to run or continue running, anddoes not control another audio and video application program, forexample, a video player in a paused state.

By means of setting a priority, a conflict caused by existence ofmultiple audio and video application programs when execution statuses ofthe audio and video application programs are controlled can beprevented. In addition, user experience can be improved because a setpriority order complies with a usage habit of a user.

Embodiment 3

Embodiment 3 is used to describe how an electronic device controls anaudio and video application program according to an action performed bya user on the electronic device, where as an example, the audio andvideo application program is a call application. In this embodiment, theelectronic device may be any mobile terminal having a call function, forexample, a mobile phone. A sensor is disposed on the mobile phone, andan external audio device is connected to the mobile phone in a wirelessmanner, where the external audio device may be specifically a Bluetoothheadset or a Bluetooth sound box. As shown in FIG. 4, the methodspecifically includes.

S41: The mobile phone receives a detection result signal sent by thesensor on the mobile phone, where the detection result signal carries adetection value that is obtained by means of detection by the sensor.

S42: The mobile phone determines, according to a preset range and thedetection value that is carried in the detection result signal, anaction performed by a user on the mobile phone.

After determining the action performed by the user on the mobile phone,the mobile phone may control a call application with reference to anexecution status of the call application. A specific control mannerincludes S43A to S43C.

S43A: When the mobile phone receives an incoming call and the actionperformed by the user on the mobile phone is moving the mobile phoneclose to a user head, the mobile phone automatically answers the calland controls call audio to be output from a built-in earpiece of themobile phone.

S43B: When the mobile phone is in a call and the action performed by theuser on the mobile phone is moving the mobile phone close to a userhead, the mobile phone controls call audio to be output from a built-inearpiece of the mobile phone.

S43C: When the mobile phone is in a call and the action performed by theuser on the mobile phone is moving the mobile phone away from a userhead, the mobile phone controls call audio to be output from theexternal audio device.

In the prior art, in a state in which the mobile phone is connected to aBluetooth device such as a Bluetooth headset or a Bluetooth sound box,if there is an incoming call in this case, the user operates the mobilephone to answer the call, and the call is output from the Bluetoothheadset or the Bluetooth sound box. If in this case the user does notknow that the mobile phone is connected to the Bluetooth headset, andcannot find the Bluetooth headset for the moment, the user further mayrequire to manually operate the mobile phone to switch a call audiooutput channel back to an earpiece of the mobile phone. Such anoperation causes trouble to the user. Alternatively, if in this case theuser does not know that the mobile phone is connected to the Bluetoothsound box, another person in a room in which the Bluetooth sound box islocated can also hear dialog content, which also causes trouble to theuser. However, according to the solution in Embodiment 3, even if theuser does not know that the mobile phone is connected to a Bluetoothdevice, the mobile phone can switch the call audio output channel to thebuilt-in earpiece of the mobile phone according to a user action ofmoving the mobile phone close to the head and with reference to anexecution status in which the mobile phone receives an incoming call oris in a call. Therefore, trouble brought to the user due to that callaudio is output from the Bluetooth device can be prevented. In addition,when the mobile phone is in a call and the user moves the mobile phoneaway from the head, the mobile phone can control call audio to be outputfrom the Bluetooth device. In such a control manner, a user intentioncan be identified, and intelligent control can be performed, so thatuser experience is better.

Embodiment 4

Embodiment 4 is used to more specifically describe, on the basis ofEmbodiment 3, how a mobile phone controls a call application accordingto an action performed by a user on the mobile phone. As shown in FIG.5, the method includes.

An initial state: A mobile phone is connected to a Bluetooth device.

S51: A mobile phone displays an incoming call reminding interface.

S52: An optical proximity sensor that is disposed on the mobile phonedetects that a user directly takes up the mobile phone and moves themobile phone close to a head to answer.

S53: The mobile phone determines whether a gesture answer function isactivated.

That is, when the mobile phone is in a call and the action performed bythe user on the mobile phone is moving the mobile phone away from a userhead, the mobile phone determines whether the gesture answer functionhas been activated for the mobile phone, where the gesture answerfunction refers to a function for the mobile phone to identify a usergesture and respond to the identified user gesture to automaticallyanswer the call. A menu option may be set in the mobile phone to enableor disable the gesture answer function.

When the mobile phone determines that the gesture answer function hasbeen activated for the mobile phone, S54Y is performed. When the mobilephone determines that the gesture answer function has not been activatedfor the mobile phone, S54N is performed.

S54Y: The mobile phone determines whether an intelligent call switchingfunction is activated.

That is, the mobile phone determines whether the intelligent callswitching function has been activated for the mobile phone, where theintelligent call switching function refers to a function for the mobilephone to automatically respond to the action performed by the user onthe mobile phone to automatically switch a call audio output channel.

When the mobile phone determines that the intelligent call switchingfunction has been activated for the mobile phone, S55Y is performed.When the mobile phone determines that the intelligent call switchingfunction has not been activated for the mobile phone, S55N is performed.

S55Y: The mobile phone automatically answers a call, and controls callaudio to be output from a built-in microphone of the mobile phone.

That is, when the intelligent call switching function has been activatedfor the mobile phone, the mobile phone automatically answers the call,and controls the call audio to be output from a built-in earpiece of themobile phone.

In an optional embodiment of Embodiment 4, when it is determined thatthe gesture answer function has been activated for the mobile phone, themobile phone may not perform S54Y to determine whether the intelligentcall switching function is activated, but may directly automaticallyanswers the call and controls the call audio to be output from thebuilt-in earpiece of the mobile phone. A menu option may be set in themobile phone to enable or disable the intelligent call switchingfunction.

S55N: The mobile phone automatically answers a call, and controls callaudio to be output from a Bluetooth device.

S54N: The mobile phone receives a user operation of slide answer or auser operation of clicking an answer button of a Bluetooth device.

S56: The mobile phone answers the call, and outputs the call audio fromthe Bluetooth device.

S57: The optical proximity sensor that is disposed on the mobile phonedetects that the user directly takes up the mobile phone and moves themobile phone close to the head to answer.

S58: The mobile phone determines whether an intelligent call switchingfunction is activated.

S59Y: The mobile phone automatically switches the call audio to thebuilt-in microphone of the mobile phone, and outputs the call audio fromthe built-in microphone.

S59N: The mobile phone controls the call audio to keep output from theBluetooth device.

According to a procedure of the method for controlling an applicationprogram that is provided in Embodiment 4, a step of determining whethera gesture answer function is activated is added, so that a user maydetermine, according to a requirement of the user, whether to enable thegesture answer function, which prevents an electricity loss from beingcaused by keeping the gesture answer function always activated. Further,an intelligent call switching function is further added, so that theuser may determine, according to a requirement of the user, whether toenable the intelligent call switching function, which prevents anelectricity loss from being caused by keeping the intelligent callswitching function always activated.

Embodiment 5

Corresponding to Embodiment 1, Embodiment 5 is used to describe anapparatus for controlling an application program that is provided in thepresent invention. The apparatus is applied to an electronic deviceconnected to an external audio device. For example, the apparatus may bea functional module disposed in the electronic device. The externalaudio device is an audio device that can be connected to the electronicdevice in a wired or wireless manner. A sensor is disposed on at leastone of the electronic device or the external audio device, where when asensor is disposed on the electronic device, the sensor disposed on theelectronic device is configured to detect that a user moves theelectronic device close to and/or away from the head of the user; andwhen a sensor is disposed on the external audio device, the sensordisposed on the external audio device is configured to detect that theuser wears and/or takes off the external audio device. The sensorincludes but is not limited to an optical proximity sensor, a lightsensor, and a temperature sensor.

As shown in FIG. 6A, the apparatus 60 includes: a receiving unit 61,configured to receive a detection result signal sent by the sensor thatis disposed on at least one of an electronic device or the externalaudio device, where the detection result signal carries a detectionvalue obtained by means of detection by the sensor; a determining unit62, configured to determine, according to a preset correspondencebetween a user action and a detection value and according to thedetection value carried in the detection result signal, an actionperformed by the user on the electronic device or the external audiodevice, where the action performed by the user on the electronic deviceincludes that the user moves the electronic device close to or away fromthe head of the user, and the action performed by the user on theexternal audio device includes that the user wears or takes off theexternal audio device; and a control unit 63, configured to control anexecution status of an audio and video application program according tothe action performed by the user on the electronic device or theexternal audio device.

In this embodiment, the receiving unit 61 receives, from a sensor thatis disposed on a headset or a main body of the electronic device, adetection value obtained by means of detection by the sensor. Thedetermining unit 62 determines, according to the detection value and apreset range that is used to determine the action performed by the useron the electronic device or the external audio device, the actionperformed by the user on the electronic device or the external audiodevice, and controls the execution status of the audio and videoapplication program according to the action. An implementation manner ofthis embodiment is similar to that of the foregoing embodiment.

For example, the electronic device is a mobile phone and the externalaudio device is a headset. A detection value acquired by a sensor thatis disposed in the headset is transmitted to a mobile phone by using theBluetooth or a sound source line. The apparatus 60 in the mobile phonedetermines and stores the foregoing detection value, and controls aparticular audio and video application program according to adetermining result (that is, an action). For example, the apparatus 60may transmit a determining result to a music module, a video module, agame module, or another module, to control the module to be paused or toplay. When a user wears a headset and is in a call, the apparatus 60 maytransmit the determining result to a call application module. If thedetermining result is that the headset is taken off, the apparatus 60controls a call to be automatically switched to a built-in earpiece ofthe mobile phone.

For a manner in which the apparatus 60 processes the detection valueacquired by the sensor that is disposed in the main body of theelectronic device, refer to the foregoing method embodiments.

According to the apparatus provided in Embodiment 5, in a state in whichthe electronic device is connected to an external audio device, theelectronic device can determine, according to a detection value acquiredby a sensor disposed on at least one of the electronic device or theexternal audio device and a preset correspondence between a user actionand a detection value, an action performed by a user on the electronicdevice or the external audio device, and control an execution status ofan audio and video application program according to the action. Theaction performed by the user on the electronic device or the externalaudio device implies a corresponding user requirement, and a mechanismprovided by this embodiment to the electronic device can determine theuser action and control the audio and video application programaccording to the user action, that is, explore the corresponding userrequirement that is implied by the user action, and perform acorresponding control action to satisfy the user requirement, whichtherefore can make a manner used by the electronic device to control, inthe state in which the electronic device is connected to the externalaudio device, the audio and video application program simpler, so thatthe user operates easily, and higher intelligentization is achieved.

Corresponding to the foregoing Embodiment 2, in a specific embodiment ofEmbodiment 5, a sensor is disposed on the external audio device, and theexternal audio device is specifically a headset. As shown in FIG. 6B,the control unit 63 specifically includes: an execution statusdetermining module 631, configured to determine a current executionstatus of the audio and video application program, where the executionstatus includes not started, running, and paused; and an executionstatus control module 632, configured to: when the action performed bythe user on the headset is taking off the headset and the executionstatus is running, control the audio and video application program to bepaused; or when the action performed by the user on the headset istaking off the headset and the execution status is not started or ispaused, control the audio and video application program to remain notstarted or remain paused; or when the action performed by the user onthe headset is wearing the headset and the execution status is notstarted or is paused, control the audio and video application program tostart to run or continue running; or when the action performed by theuser on the headset is wearing the headset and the execution status isrunning, control the audio and video application program to remainrunning.

In addition, to prevent an error from occurring in control by thecontrol unit 63 when there are multiple audio and video applicationprogram, the control unit 63 is further configured to: in a case inwhich there are multiple audio and video application programs, determinethat an audio and video application program having a highest priority isan audio and video application program that may require to be controlledby the control unit 63 according to the action performed by the user onan external electronic device or the electronic device.

Corresponding to the foregoing Embodiment 3, in another specificembodiment of Embodiment 5, a sensor is disposed on the electronicdevice, the audio and video application program is specifically a callapplication, and the external audio device is connected to theelectronic device in a wireless manner. The control unit 63 isspecifically configured to: when the electronic device receives anincoming call and the action performed by the user on the electronicdevice is moving the electronic device close to the head of the user,automatically answer the call, and control call audio to be output froma built-in earpiece of the electronic device; or when the electronicdevice is in a call and the action performed by the user on theelectronic device is moving the electronic device close to the head ofthe user, control call audio to be output from a built-in earpiece ofthe electronic device; or when the electronic device is in a call andthe action performed by the user on the electronic device is moving theelectronic device away from the head of the user, control call audio tobe output from the external audio device.

Corresponding to Embodiment 4, in still another more specific embodimentof Embodiment 5, the control unit 63 can further determine whether agesture answer function has been activated for the electronic device.The control unit 63 is specifically configured to: when the electronicdevice receives an incoming call and the action performed by the user onthe electronic device is moving the electronic device close to the headof the user, determine whether a gesture answer function has beenactivated for the electronic device, where the gesture answer functionrefers to a function for the electronic device to identify a usergesture and respond to the identified user gesture to automaticallyanswer the call; and when the gesture answer function has been activatedfor the electronic device, control the electronic device toautomatically answer the call, and control the call audio to be outputfrom the built-in earpiece of the electronic device.

More specifically, the control unit 63 can further determine whether anintelligent call function has been activated for the electronic device.The control unit 63 is specifically configured to determine whether anintelligent call switching function has been activated for theelectronic device, where the intelligent call switching function refersto a function for the electronic device to automatically respond to theaction performed by the user on the electronic device to automaticallyswitch a call audio output channel; and when the intelligent callswitching function has been activated for the electronic device, controlthe electronic device to automatically answer the call, and control thecall audio to be output from the built-in earpiece of the electronicdevice; or when the intelligent call switching function is not activatedfor the electronic device, control the electronic device toautomatically answer the call, and control the call audio to be outputfrom the external audio device.

Embodiment 6

Corresponding to Embodiment 1, Embodiment 6 is used to describe anelectronic device provided in the present invention. The electronicdevice is connected to an external audio device. The external audiodevice is an audio device that can be connected to the electronic devicein a wired or wireless manner. A sensor is disposed on at least one ofthe electronic device or the external audio device, where when a sensoris disposed on the electronic device, the sensor disposed on theelectronic device is configured to detect that a user moves theelectronic device close to or away from the head of the user; and when asensor is disposed on the external audio device, the sensor disposed onthe external audio device is configured to detect that the user wearsand/or takes off the external audio device.

FIG. 7 is a schematic structural diagram of the electronic deviceaccording to Embodiment 6. As shown in FIG. 7, the electronic device 70in this embodiment includes: at least one receiver 71, a processor 72,and a bus. By using the bus, the receiver 71 and the processor 72 areconnected to each other and communicate with each other. The bus may bean Industry Standard Architecture (ISA for short) bus, a PeripheralComponent Interconnect (PCI for short) bus, an Extended IndustryStandard Architecture (EISA for short) bus, or the like. The bus may beclassified into an address bus, a data bus, a control bus, or the like.For convenience of indication, the bus is indicated by using only onebold line in FIG. 7, which, however, does not indicate that there isonly one bus or one type of bus. As shown in FIG. 7, the electronicdevice 70 includes: the receiver 71, configured to receive a detectionresult signal sent by the sensor that is disposed on at least one of theelectronic device 70 or the external audio device, where the detectionresult signal carries a detection value obtained by means of detectionby the sensor; and the processor 72, configured to determine, accordingto a preset correspondence between a user action and a detection valueand according to the detection value carried in the detection resultsignal, an action performed by the user on the electronic device 70 orthe external audio device, where the action performed by the user on theelectronic device 70 includes that the user moves the electronic device70 close to or away from the head of the user, and the action performedby the user on the external audio device includes that the user wears ortakes off the external audio device, where the processor 72 is furtherconfigured to control an execution status of an audio and videoapplication program according to the action performed by the user on theelectronic device 70 or the external audio device.

According to the electronic device 70 provided in Embodiment 6, theelectronic device 70 can explore a corresponding user requirement thatis implied by the action performed by the user on the electronic device70 or the external audio device, and perform a corresponding controlaction to satisfy the user requirement, which therefore can make amanner used by the electronic device to control, in the state in whichthe electronic device 70 is connected to the external audio device, theaudio and video application program simpler, so that the user operateseasily, and higher intelligentization is achieved.

Corresponding to Embodiment 2, in a specific embodiment of Embodiment 6,a sensor is disposed on the external audio device, and the externalaudio device is specifically a headset. The processor 72 is specificallyconfigured to: determine a current execution status of the audio andvideo application program, where the execution status includes notstarted, running, and paused; and when the action performed by the useron the headset is taking off the headset and the execution status isrunning, control the audio and video application program to be paused;or when the action performed by the user on the headset is taking offthe headset and the execution status is not started or is paused,control the audio and video application program to remain not started orremain paused; or when the action performed by the user on the headsetis wearing the headset and the execution status is not started or ispaused, control the audio and video application program to start to runor continue running; or when the action performed by the user on theheadset is wearing the headset and the execution status is running,control the audio and video application program to remain running.

To prevent an error from occurring in control by the processor 72 whenthere are multiple audio and video application programs, the processor72 is further configured to: in a case in which there are multiple audioand video application programs, determine that an audio and videoapplication program having a highest priority is an audio and videoapplication program that may require to be controlled by the processor72 according to the action performed by the user on the electronicdevice and the external audio device.

Corresponding to Embodiment 3, in another specific embodiment ofEmbodiment 6, a sensor is disposed on the electronic device 70, theexternal audio device is connected to the electronic device 70 in awireless manner, and the audio and video application program isspecifically a call application. The processor 72 is specificallyconfigured to: when the electronic device 70 receives an incoming calland the action performed by the user on the electronic device 70 ismoving the electronic device 70 close to the head of the user, controlthe electronic device 70 to automatically answer the call, and controlcall audio to be output from a built-in earpiece of the electronicdevice 70; or when the electronic device 70 is in a call and the actionperformed by the user on the electronic device 70 is moving theelectronic device 70 close to the head of the user, control call audioto be output from a built-in earpiece of the electronic device 70; orwhen the electronic device 70 is in a call and the action performed bythe user on the electronic device 70 is moving the electronic device 70away from the head of the user, control call audio to be output from theexternal audio device.

Corresponding to Embodiment 4, in still another more specific embodimentof Embodiment 6, the processor 72 is specifically configured to: whenthe electronic device 70 receives an incoming call and the actionperformed by the user on the electronic device 70 is moving theelectronic device 70 close to the head of the user, determine whether agesture answer function has been activated for the electronic device 70,where the gesture answer function refers to a function for theelectronic device to identify a user gesture and respond to theidentified user gesture to automatically answer the call; and when thegesture answer function has been activated for the electronic device 70,control the electronic device 70 to automatically answer the call, andcontrol the call audio to be output from the built-in earpiece of theelectronic device 70.

More specifically, more specifically, the processor 72 can furtherdetermine whether an intelligent call function has been activated forthe electronic device 70. The processor 72 is specifically configured todetermine whether an intelligent call switching function has beenactivated for the electronic device 70, where the intelligent callswitching function refers to a function for the electronic device toautomatically respond to the action performed by the user on theelectronic device to automatically switch a call audio output channel;and when the intelligent call switching function has been activated forthe electronic device 70, control the electronic device 70 toautomatically answer the call, and control the call audio to be outputfrom the built-in earpiece of the electronic device 70; or when theintelligent call switching function is not activated for the electronicdevice 70, control the electronic device 70 to automatically answer thecall, and control the call audio to be output from the external audiodevice.

The embodiments in this specification are described with emphasis, forsame or similar parts in the embodiments, cross-reference may be made,and each embodiment focuses on a difference from another embodiment.Especially, an apparatus embodiment is basically similar to a methodembodiment, and therefore is described briefly; for related parts,reference may be made to partial descriptions in the method embodiment.

It should be noted that the described apparatus embodiment is merelyexemplary. The units described as separate parts may or may not bephysically separate, and parts displayed as units may or may not bephysical units, may be located in one position, or may be distributed ona plurality of network units. Some or all of the modules may be selectedaccording to actual requirements to achieve the objectives of thesolutions of the embodiments. In addition, in the accompanying drawingsof the apparatus embodiments provided by the present invention,connection relationships between the modules indicate that the moduleshave communication connections with each other, which may bespecifically implemented as one or more communications buses or signalcables. A person of ordinary skill in the art may understand andimplement the embodiments of the present invention without creativeefforts.

A person of ordinary skill in the art may understand that, each aspectof the present invention or a possible implementation manner of eachaspect may be specifically implemented as a system, a method, or acomputer program product. Therefore, each aspect of the presentinvention or a possible implementation manner of each aspect may useforms of hardware only embodiments, software only embodiments (includingfirmware, resident software, and the like), or embodiments with acombination of software and hardware, which are uniformly referred to as“circuit”, “module”, or “system” herein.

The foregoing descriptions are merely specific implementation manners ofthe present invention, but are not intended to limit the protectionscope of the present invention. Any variation or replacement readilyfigured out by a person skilled in the art within the technical scopedisclosed in the present invention shall fall within the protectionscope of the present invention. Therefore, the protection scope of thepresent invention shall be subject to the protection scope of theclaims.

1. A terminal device, comprising: a processor; and a memory coupled tothe processor and configured to store processor-executable instructionsthat, when executed by the processor, cause the terminal device to:receive an incoming call; automatically answer the incoming call andoutput a call audio of the incoming call from a built-in earpiece of theterminal device when the terminal device is moving to a user's head,when a gesture answer function is activated, and when an intelligentcall switching function is activated; and automatically answer theincoming call and output the call audio from an external audio devicecoupled to the terminal device when the terminal device is moving to theuser's head, when the gesture answer function is activated, and when theintelligent call switching function is not activated.
 2. The terminaldevice of claim 1, further comprising a display configured to display anincoming call reminding interface of the incoming call.
 3. The terminaldevice of claim 1, further comprising an optical proximity sensorconfigured to detect the terminal device is moving to the user's head.4. The terminal device of claim 3, wherein the optical proximity sensoris further configured to detect that the terminal device is moving awayfrom the user's head, and wherein the processor is further configured toexecute the instructions stored in the memory to cause the terminaldevice further to control the output of the call audio of the incomingcall from the external audio device.
 5. The terminal device of claim 1,wherein the processor is further configured to execute the instructionsstored in the memory to cause the terminal device further to set a menuoption for activating or inactivating the gesture answer function. 6.The terminal device of claim 1, wherein the processor is furtherconfigured to execute the instructions stored in the memory to cause theterminal device further to: detect that the terminal device is movingaway from the user's head; and output the call audio of the incomingcall from the external audio device.
 7. A communications method,implemented in a terminal device connected with an external audiodevice, wherein the communications method comprises: receiving a firstincoming call; automatically answering the first incoming call andcontrolling a call audio of the first incoming call to be output from abuilt-in earpiece of the terminal device, wherein the terminal device ismoved to a user's head, wherein a gesture answer function is activated,and wherein an intelligent call switching function is activated;receiving a second incoming call; and automatically answering the secondincoming call and controlling the call audio to be output from theexternal audio device, wherein the terminal device is moved to theuser's head, wherein the gesture answer function is activated, andwherein the intelligent call switching function is not activated.
 8. Thecommunications method of claim 7, wherein after receiving the firstincoming call, the communications method further comprises displaying anincoming call reminding interface of the first incoming call.
 9. Thecommunications method of claim 7, further comprising detecting when theterminal device is moving to the user's head using an optical proximitysensor disposed on the terminal device.
 10. The communications method ofclaim 7, further comprising setting a menu option for activating orinactivating the gesture answer function.
 11. The communications methodof claim 7, further comprising: detecting that the terminal device ismoving away from the user's head; and outputting the call audio of thefirst incoming call from the external audio device.
 12. Thecommunications method of claim 7, wherein the external audio devicecomprises a headset.
 13. A communications method, implemented in aterminal device connected with an external audio device, wherein thecommunications method comprises: receiving an incoming call; receiving afirst user operation of answering the incoming call or a second useroperation of clicking an answer button of the external audio device;answering the incoming call and outputting call audio from the externalaudio device; and automatically switching the call audio to a built-inearpiece of the terminal device and outputting the call audio from thebuilt-in earpiece when the terminal device is moved to a user's head andwhen an intelligent call switching function is activated.
 14. Thecommunications method of claim 13, wherein after receiving the incomingcall, the communications method further comprises displaying an incomingcall reminding interface of the incoming call.
 15. The communicationsmethod of claim 13, further comprising detecting when the terminaldevice is moving to the user's head using an optical proximity sensordisposed on the terminal device.
 16. The communications method of claim13, further comprising setting a menu option for activating orinactivating the intelligent call switching function.
 17. A terminaldevice, comprising: a processor; and a memory coupled to the processorand configured to store processor-executable instructions that, whenexecuted by the processor, cause the terminal device to: receive anincoming call; receive a first user operation of answering the incomingcall or a second user operation of clicking an answer button of anexternal audio device; answer the incoming call and output call audiofrom the external audio device; and automatically switch the call audioto a built-in earpiece of the terminal device and output the call audiofrom the built-in earpiece when the terminal device is moved to a user'shead and when an intelligent call switching function is activated. 18.The terminal device of claim 17, further comprising an optical proximitysensor configured to detect that the terminal device is moved to theuser's head.
 19. The terminal device of claim 17, wherein the processoris further configured to execute the instructions stored in the memoryto cause the terminal device to set a menu option for activating orinactivating the intelligent call switching function.
 20. The terminaldevice of claim 17, wherein the processor is further configured toexecute the instructions stored in the memory to cause the terminaldevice to: detect the terminal device is moved away from the user'shead; and switch the call audio from the built-in earpiece of theterminal device to the external audio device.